package com.disthen.message.core.config;

import java.util.Date;
import java.util.Random;

import org.springframework.beans.factory.InitializingBean;

public class Template implements InitializingBean{

	public final static String TPL_NAME_PREFIX = "disthen.message.Template";
	
	private String name;
	private String exchangeName;
	private String converter;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getExchangeName() {
		return exchangeName;
	}

	public void setExchangeName(String exchangeName) {
		this.exchangeName = exchangeName;
	}

	public String getConverter() {
		return converter;
	}

	public void setConverter(String converter) {
		this.converter = converter;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		if(this.exchangeName == null || this.exchangeName.isEmpty()){
			throw new NullPointerException("com.disthen.message.core.config.Template 中 exchangeName 属性不能为空！");
		}
		if(this.name == null || this.name.isEmpty()){
			this.name = TPL_NAME_PREFIX + "-" + new Random(new Date().getTime()).nextInt();
		}
	}
}
